package com.killer.util;


import java.util.Random;

/**
 * @author ：Killer
 * @date ：Created in 20-12-31 下午3:50
 * @description：${description}
 * @modified By：
 * @version: version
 */
public class CodeUtil {

    private static Random random = new Random();

    private static String codes = "0123456789";

    /**
     * 生成随机字符串
     * @param codeLength
     * @return
     */
    public static String generateCode(int codeLength) {
        //用来装载生成的验证码文本
        StringBuilder sb = new StringBuilder();
        // 向图片中画4个字符
        for (int i = 0; i < codeLength; i++) {
            sb.append(randomChar());
        }

        return sb.toString();
    }

    /**
     * 随机生成一个字符
     */
    private static char randomChar() {
        int index = random.nextInt(codes.length());
        return codes.charAt(index);
    }

    public static void main(String[] args) {
        System.out.println(generateCode(6));
    }


}
